/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef __MaCI_BehaviourFrame__
#define __MaCI_BehaviourFrame__

/**
@file
Subclass of Frame, which is generated by wxFormBuilder.
*/

#include "MaCI_Behaviour_GUI.h"
#include "BehaviourClient.hpp"
#include "Component.hpp"
#include "owndebug.h"
#include "ownutils.h"
/** Implementing Frame */

// Custom events.
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(MY_EVENT_REFRESHSPEEDVALUES, -1)
DECLARE_EVENT_TYPE(MY_EVENT_REFRESHBEHAVIOURCOLORS,-1)
END_DECLARE_EVENT_TYPES();

class MaCI_BehaviourFrame :  private gim::CSync,
                             private gim::CThread,
                             public Frame,
                             public Gimbo::CComponent,
                             public MaCI::Behaviour::CBehaviourClientCallback
{
  DECLARE_EVENT_TABLE();
 protected:
  // Handlers for Frame events.
  void OnItemActivate( wxListEvent& event );
  void OnItemSelected( wxListEvent& event );
  void OnStartStopButton( wxCommandEvent& event );
  void OnServiceAssignment(const Gimbo::TServiceAssignmentList &aServiceList);  

  void OnNewSpeedValues(wxCommandEvent &aEvent);
  void OnNewBehaviourState(wxCommandEvent &aEvent);
  

 public:
  /** Constructor */
  MaCI_BehaviourFrame( wxWindow* parent );
  virtual ~MaCI_BehaviourFrame();
  
  bool Initialize(gimi::GIMI *aGimiPtr, int aGimboID, int aReportID);
  void Deinitialize(void);
  
  void OnBehaviourCtrlEvent(const MaCI::Behaviour::CBehaviourData &aData, 
                            const unsigned int aDataSequence,
                            MaCI::Behaviour::CBehaviourClient &aBehaviourClient);
  
  void OnBehaviourStateEvent(const MaCI::Behaviour::CBehaviourData &aData, 
                             const unsigned int aDataSequence,
                             MaCI::Behaviour::CBehaviourClient &aBehaviourClient);
  private:
  void DisconnectServices(void);
  bool ConnectServices(void);
  int ThreadFunction(const int aThreadNumber);

  std::vector<MaCI::Behaviour::CBehaviourData> iBControllingDataArray; 
  std::vector<gim::time> iBControllingValueTime;
  std::vector<bool> iBehaviourControlling;

  std::vector<bool> iBehaviourStates;
 

  Gimbo::TServiceAssignmentList iServiceList;
  bool iServiceListUpdated;
  gimi::GIMI *iGIMIPtr;
  int iSelectedBehaviour;
  std::vector<MaCI::Behaviour::CBehaviourClient *> iBehaviourClientArray;
  bool iThreadRunning;
};

#endif // __MaCI_BehaviourFrame__
